package com.imay.live.manager;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.zhouwei.library.CustomPopWindow;
import com.imay.live.R;
import com.imay.base.util.SpannableStringUtils;
import com.imay.live.utils.ViewUtil;

/**
 * Created by Administrator on 2017/8/2.
 */

public class GuideManager {

    /**
     * 直播间星钻引导气泡
     *
     * @param activity
     */
    public static void showDiamonGuideDialog(Activity activity, long diamonCount,View view) {
        if(activity == null || activity.isFinishing()){
            return;
        }
        View contentLiveView = LayoutInflater.from(activity).inflate(R.layout.dialog_diamon, null);
        TextView tv_content_diamon_room_live = ViewUtil.findView(contentLiveView, R.id.tv_content_diamon_room_live);
        SpannableStringUtils.Builder builder=SpannableStringUtils.getBuilder(activity.getString(R.string.diamon_guide1));
        builder.append(diamonCount+"").setForegroundColor(activity.getResources().getColor(R.color.text_ffc));
        builder.append(activity.getString(R.string.diamon_guide2));
        tv_content_diamon_room_live.setText(builder.create());
        final CustomPopWindow mListLivePopWindow = new CustomPopWindow.PopupWindowBuilder(activity)
                    .setView(contentLiveView)
                    .setOutsideTouchable(false)
                    .size(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)//显示大小
                    .create();
        contentLiveView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int popupHeight = contentLiveView.getMeasuredHeight();
        mListLivePopWindow.showAsDropDown(view,0,- (view.getHeight() + popupHeight));
        contentLiveView.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (mListLivePopWindow != null) {
                    mListLivePopWindow.dissmiss();
                }
            }
        }, 3000);
    }

}
